<?php
/**
 * This is media/admin_index template file. 
 *
 * @copyright     Copyright 2008-2010, LilCake.net
 * @link          http://lilcake.net LilCake.net
 * @package       lil_media
 * @subpackage    lil_media.views.areas
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
	echo $this->Html->css('/lil_media/css/lil_media');
	
	$path_parts = pathinfo($base_path . DS . $filename);
	
	$media_index = array(
		'title_for_layout' => __d('lil_media', 'View File'),
		'menu' => array(
			'add' => array(
				'title' => __d('lil_media', 'Delete', true),
				'visible' => true,
				'url'   => array(
					'admin'      => true,
					'plugin'     => 'lil_media',
					'controller' => 'media',
					'action'     => 'delete',
					'path'       => (!empty($this->request->params['named']['path'])) ?
						$this->request->params['named']['path'] : null,
					'filename'   => base64_encode($path_parts['basename'])
				)
			)
		),
		'panels' => array(
			'index' => array(
				'id' => 'ViewMedia',
				'lines' => array(
				)
			)
		)
	);

	
	$icon = '';  $item_url = ''; $item_class = '';
	$item_title = $www_dir . $path_parts['basename'];
	
	if (in_array(strtolower($path_parts['extension']), array('gif', 'png', 'jpg'))) {
		$icon = $this->Html->image($www_dir . $path_parts['basename']);
		$item_url = $www_dir . $path_parts['basename'];
		$item_class = ' lil-media-view-image';
	} else if (in_array(strtolower($path_parts['extension']), array('doc', 'docx'))) {
		$icon = $this->Html->image('/lil_media/img/doc.gif');
	} else if (in_array(strtolower($path_parts['extension']), array('xls', 'xlsx'))) {
		$icon = $this->Html->image('/lil_media/img/xls.gif');
	} else if (strtolower($path_parts['extension']) == 'pdf') {
		$icon = $this->Html->image('/lil_media/img/pdf.gif');
	} else {
		$icon = $this->Html->image('/lil_media/img/x.gif');
	}
	
	if (empty($item_url)) {
		$item_url = array(
			'admin'  => true,
			'action'   => 'download',
			'path'     => (!empty($this->params['named']['path'])) ?
				$this->params['named']['path'] : null,
			'filename' => base64_encode($path_parts['basename'])
		);
	}
	
	$media_index['panels']['index']['lines'][] = sprintf('<div id="ViewMediaItem">%s</div>',
		$this->Html->link(
			$icon,
			$item_url,
			array(
				'escape' => false,
				'class'  => 'lil-media-view-item' . $item_class,
				'title'  => $item_title
			)
		)
	);
	
	$media_index['panels']['index']['lines'][] = sprintf(
		'<div class="view_media_item_row"><span class="label">%1$s: </span>%2$s</div>',
		__d('lil_media', 'Filename'),
		$this->Html->link(
			$path_parts['basename'],
			array(
				'admin'  => true,
				'action' => 'download',
				'path'   => (!empty($this->params['named']['path'])) ?
					$this->params['named']['path'] : null,
				'filename'   => base64_encode($path_parts['basename'])
			)
		)
	);
	
	$media_index['panels']['index']['lines'][] =  sprintf(
		'<div class="view_media_item_row"><span class="label">%1$s: </span><span class="value">%2$s</span></div>',
		__d('lil_media', 'Path'), $www_dir
	);
	
	$media_index['panels']['index']['lines'][] =  sprintf(
		'<div class="view_media_item_row"><span class="label">%1$s: </span><span class="value">%2$s</span></div>',
		__d('lil_media', 'File size'), $this->Number->toReadableSize($data['size'])
	);
	
	
	if (in_array(strtolower($path_parts['extension']), array('gif', 'png', 'jpg'))) {
		$dims = getimagesize($full_path . DS . $filename);
		$media_index['panels']['index']['lines'][] =  sprintf(
			'<div class="view_media_item_row"><span class="label">%1$s: </span><span class="value">%2$s</span></div>',
			__d('lil_media', 'Dimensions'), __d('lil_media', '%1$s x %2$s px', $dims[0], $dims[1])
		);
	}
	
	$media_index = $this->callPluginHandlers('lil_media_media_admin_view', array('data' => $data, 'contents' => $media_index));
	$this->Lil->panels($media_index['contents']);
	
	
	if (in_array(strtolower($path_parts['extension']), array('gif', 'png', 'jpg'))) {
	
	echo $this->Html->css('/lil_media/css/fancybox/jquery.fancybox-1.3.1');
	echo $this->Html->script('/lil_media/js/jquery-1.4.2.min');
	echo $this->Html->script('/lil_media/js/jquery.fancybox-1.3.1.pack');
	
?>
	<script type="text/javascript">
		$(document).ready(function() {
			$(".lil-media-view-image").fancybox();
		});
	</script>
<?php
	}
?>